// pages/my/my.js
var api = require("../../utils/api.js")
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        Tpye: 0,
        userInfo: [],
    },
    //编辑
    myeditor: function() {
        wx.navigateTo({
            url: '../myeditor/myeditor',
        })
    },
    //登录
    login: function() {
        wx.navigateTo({
            url: '../login/login',
        })
        wx.navigateBack({
            delta: 1
        })
    },
    //订单
    myorder: function() {
        if (this.data.Tpye) {
            wx.navigateTo({
                url: '../myreservation/myreservation',
            })
        } else {
            wx.navigateTo({
                url: '../login/login'
            })
        }

    },
    //客服
    customer: function(e) {
        wx.navigateTo({
            url: '/pages/thetext/thetext?id=' + e.currentTarget.dataset.id,
        })
    },
    //我的预约
    focus: function() {
        if (this.data.Tpye) {
            wx.navigateTo({
                url: '../myfocus/myfocus',
            })
        } else {
            wx.navigateTo({
                url: '../login/login'
            })
        }
    },
    //修改密码
    modifythe: function() {
        wx.navigateTo({
            url: '../modifythe/modifythe',
        })
    },
	groupin(e){
		wx.navigateTo({
			url: '../groupjoin/groupjoin',
		})
	},
    //意见反馈
    myfeedback: function() {
        wx.navigateTo({
            url: '../myfeedback/myfeedback',
        })
    },
    goidenti: function() {
        if (this.data.Tpye) {
            wx.navigateTo({
                url: '../registerstep/registerstep'
            })
        } else {
            wx.navigateTo({
                url: '../login/login'
            })
        }
    },
    psyset: function(e) {
        if (this.data.Tpye) {
            wx.navigateTo({
                url: '../consultlist/consultlist'
            })
        } else {
            wx.navigateTo({
                url: '../login/login'
            })
        }
    },
    consultantorder: function(e) {
        if (this.data.Tpye) {
            wx.navigateTo({
                url: '../consultantorder/consultantorder'
            })
        } else {
            wx.navigateTo({
                url: '../login/login'
            })
        }

    },
    cleaor: function() {
        var that = this
        wx.clearStorage({
            key: 'userInfo',
            success: function() {
                api.showError("退出登录")
                setTimeout(function() {
                    wx.navigateTo({
                        url: '../login/login',
                    })
                    that.setData({
                        Tpye: 0
                    })
                }, 800)
            },
            fail: function() {
                api.showError("退出失败")
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        //  wx.getStorage({
        // 	 key: 'userInfo',
        // 	 success: function(res) {

        // 	 },
        // 	 fail:function(){
        // 		 setTimeout(function () {
        // 			 wx.navigateTo({
        // 				 url: '../login/login',
        // 			 })
        // 		 }, 800)
        // 	 }
        //  })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        var that = this
        wx.getStorage({
            key: 'userInfo',
            success(res) {
                let data = { id: res.data.id }
                let url = app.u.HOME_URL + app.u.ME_NEWINFO
                api.requestUrl(data, url).then(res => {
                    that.setData({
                        userInfo: res.data,
                        Tpye: 1,
                    })
                    wx.setStorage({
                        key: 'userInfo',
                        data: res.data
                    })
                })

            },
            fail(res) {

            }
        })
        wx.showShareMenu({
            withShareTicket: true
        })
    },


})